<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Encryption\DecryptException;

class CheckAdminLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $token = $request->header('access-token');
        if(empty($token))
        {
            return response()->json(['code' => 401,'message' => '未设置access_token','status' => 200,'exception' => '','data' => (object)[]]);
        }

        try
        {
            $adminuser = decrypt($token);
        }
        catch (DecryptException $e)
        {
            return response()->json(['code' => 401,'message' => '未设置access_token','status' => 200,'exception' => '','data' => (object)[]]);
        }

        return $next($request);
    }
}
